<!-- 开箱列表 -->
<template>
  <div class="page-box h100 display-flex czbj">
    <p class="title-label">开箱列表</p>
    <div class="btm mt10 pt10">
      <dxtable
        :dataJson="dataJson"
        :portUrl="portUrl"
        :qx="qx"
        ref="databale"
        :formJson="formJson"
        imgkuTitle="新闻图片"
        :czFun="czFun"
        czWidth="350"
        bjtext="修改"
      ></dxtable>
    </div>
  </div>
</template>
 <script lang='ts' setup>
import dxtable from "../../../components/util/dxtable.vue";
import sort from "../../../components/util/sort.vue";
import { NSwitch } from "naive-ui";
import { dxget, dxpost, qurl, hf, dxdownFile } from "../../../util/index";
import { h, ref, reactive } from "vue";
import { NButton } from "naive-ui";
const cz = qurl();
const databale = ref();
const initeer = () => {
  databale.value.initDataExpose();
};

// 弹窗公用该列表
let dataJson = reactive([
  {
    title: "机器序列号",
    key: "ModelNo",
  },
  {
    title: "AC项目号",
    key: "itemNumber",
  },
  {
    title: "项目名称",
    key: "projectName|ModelNo|itemNumber", //多个关键字搜索
    placeholder: "输入关键字查询",
    search: true, // 是否再搜索栏展示
    render(row) {
      return row.projectName;
    },
  },
  {
    title: "机型",
    key: "millType",
    type: "select",
    options: [],
  },
  {
    title: "布置方式",
    type: "select",
    options: [],
    key: "arrangementForm",
  },
  {
    title: "验证码",
    key: "verificationCode",
  },

  {
    title: "排序",
    width: 100,
    render(row) {
      row.databaseName = "kxunpack";
      return h(sort, {
        row,
        onCallBack: () => {
          initeer();
        },
      });
    },
  },
  {
    title: "验收时间",
    key: "addTime",
    width: "200",
    type: "daterange",
    search: true, // 是否再搜索栏展示
  },
]);
let portUrl = "kx/kxunpack";
const qx = {
  DeletePermissionID: "kxlistdel", //删除
  EditPermissionIdentifier: "kxlistbj", // 编辑
  NewPermissionIdentifier: "kxlistxz", // 新建
  ViewPermissionID: "kxlistck", // 查看
};

let formJson = reactive([
  {
    title: "机器序列号",
    key: "ModelNo",
    type: "input",
    required: true,
  },
  {
    title: "AC项目号",
    key: "itemNumber",
    type: "input",
    required: true,
  },
  {
    title: "项目名称",
    key: "projectName",
    type: "input",
    required: true,
  },
  {
    title: "机型",
    key: "millType",
    type: "select",
    options: [],
    required: true,
  },
  {
    title: "布置方式",
    key: "arrangementForm",
    type: "select",
    options: [],
    required: true,
  },
  {
    title: "验证码",
    key: "verificationCode",
    type: "input",
    required: true,
  },
  {
    title: "验证重复的验证码",
    key: "thenAdd",
    val: "verificationCode",
  },
  {
    title: "验证重复的验证码",
    key: "errmsg",
    val: "已存再相同的验证码",
  },
]);
const setXl = (text, data) => {
  const kjhaea = [];
  data.split(",").map((a) => {
    let obj = {
      label: a,
      value: a,
    };
    kjhaea.push(obj);
  });
  formJson.filter((a) => a.key == text)[0].options = kjhaea;
  dataJson.filter((a) => a.key == text)[0].options = kjhaea;
};

const initSelect = async () => {
  const { data }: any = await dxget("beRelieved/dictionaries?type=2", {
    id: 26,
  });
  if (data.dlabel) {
    setXl("millType", data.dlabel);
  }

  const res: any = await dxget("beRelieved/dictionaries?type=2", {
    id: 27,
  });
  if (res.data.dlabel) {
    setXl("arrangementForm", res.data.dlabel);
  }
};
initSelect();
const czFun = {
  fun: (row, loading) => {
    return [
      h(
        NButton,
        {
          type: "info",
          quaternary: true,
          onClick: async (e) => {
            hf("kxboxManagement", { id: row.id });
          },
        },
        "箱子管理"
      ),
      h(
        NButton,
        {
          type: "info",
          quaternary: true,
          onClick: async (e) => {
            const res: any = await dxget("kx/util/getsingqm", {
              id: row.id,
            });
            if (res.data <= 0) {
              window.$message.error("暂无已验收的箱子，请先验收再操作！");
              return;
            }
            loading.value = true;
            const { data }: any = await dxget("util/urlzpdf", {
              url: "https://duxinggj.com/kx/OutOfTheReportZt?id=" + row.id,
            });
            loading.value = false;
            open(data);
          },
        },
        "整体开箱报告"
      ),
      h(
        NButton,
        {
          type: "info",
          quaternary: true,
          onClick: async (e) => {
            const res: any = await dxget("kx/util/getsingqm", {
              id: row.id,
            });
            if (res.data <= 0) {
              window.$message.error("暂无已验收的箱子，请先验收再操作！");
              return;
            }
            loading.value = true;
            const { data }: any = await dxget("util/urlzpdf", {
              url: "https://duxinggj.com/kx/OutOfTheSummary?id=" + row.id,
            });
            loading.value = false;
            open(data);
          },
        },
        "开箱纪要"
      ),
    ];
  },
};
</script>
 <style scoped>
</style>


